import { axiosInstance } from 'src/boot/axios'
import CommonConfig from 'src/assets/js/config'

const cutterUrl = CommonConfig.cutterUrl + '/v1'

/**
 * 列举库位
 * @returns {Promise<unknown>}
 */
export function getStorageLocationList (params, warehouseId) {
  const url = `${cutterUrl}/warehouses/${warehouseId}/storageLocations:page`

  return axiosInstance.get(url, { params }).then(resp => {
    return Promise.resolve(resp.data)
  })
}

/**
 * 添加库位
 * @returns {Promise<unknown>}
 */
export function addStorageLocation (params, warehouseId) {
  const url = `${cutterUrl}/warehouses/${warehouseId}/storageLocations`

  return axiosInstance.post(url, params).then(resp => {
    return Promise.resolve(resp)
  })
}

/**
 * 编辑库位
 * @returns {Promise<unknown>}
 */
export function editStorageLocation (params, id) {
  const url = cutterUrl + '/warehouses/storageLocations/' + id

  return axiosInstance.patch(url, params).then(resp => {
    return Promise.resolve(resp)
  })
}

/**
 * 删除库位
 * @returns {Promise<unknown>}
 */
export function delStorageLocation (id) {
  const url = cutterUrl + '/warehouses/storageLocations/' + id

  return axiosInstance.delete(url).then(resp => {
    return Promise.resolve(resp)
  })
}
